package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 上传小视频
     *
     * @param videoThumbnail 封面
     * @param videoFile      视频文件
     * @return
     */
    @PostMapping
    public ResponseEntity add(MultipartFile videoThumbnail, MultipartFile videoFile) {
        // 接收参数，调用业务
        videoService.add(videoThumbnail, videoFile);
        // 响应结果
        return ResponseEntity.ok(null);
    }

    /**
     * 小视频分页列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseEntity findPage(@RequestParam(value = "page", defaultValue = "1") Long page,
                                   @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize) {
        PageResult pageResult = videoService.findPage(page, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 关注小视频的作者
     * @param authorId
     * @return
     */
    @PostMapping("/{authorId}/userFocus")
    public ResponseEntity followUser(@PathVariable Long authorId){
        videoService.followUser(authorId);
        return ResponseEntity.ok(null);
    }

    /**
     * 取消小视频的作者关注
     * @param authorId
     * @return
     */
    @PostMapping("/{authorId}/userUnFocus")
    public ResponseEntity unfollowUser(@PathVariable Long authorId){
        videoService.unfollowUser(authorId);
        return ResponseEntity.ok(null);
    }
}
